package com.domain.service.impl;

import com.alibaba.fastjson.JSON;
import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsResponse;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.domain.common.AppLogger;
import com.domain.common.Result;
import com.domain.service.RedisService;
import com.domain.service.SmsService;
import com.domain.utils.NotNullUtils;
import com.domain.utils.RandomUtils;
import com.domain.utils.UUIDUtils;
import com.domain.utils.message.AliyunSmsUtils;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
public class SmsServiceImpl implements SmsService {


    /**
     * 日志
     */
    private static Logger logger = AppLogger.getLogger(ContactsServiceImpl.class.getSimpleName(), Level.INFO.toString(), true);
    @Autowired
    private RedisService redisService;


    /**
     * 发送短信
     *
     * @param mobile 手机号
     * @return
     */
    @Override
    public Result sendMessage(String mobile, String radom) throws ClientException {
        //发送短信
        /* SendSmsResponse response = AliyunSmsUtils.sendSmsResgster(mobile, radom);*/
        //保存验证码到redis
        redisService.setKey(mobile, radom);
       /* if (response.getCode().equals("200")) {

        } else if (response.getCode().equals("isv.AMOUNT_NOT_ENOUGH")) {
            return Result.fail("账户余额不足");
        }*/
        return Result.success(radom);
    }

    /**
     * 判断验证码是否正确
     *
     * @param mobile
     * @param identifyCode
     * @return
     */
    @Override
    public boolean checkIsCorrectCode(String mobile, String identifyCode) {
        String returnCode = redisService.getValue(mobile);
        if (NotNullUtils.isNotNullObject(returnCode) && returnCode.equals(identifyCode)) {
            return true;
        }
        return false;
    }
}
